<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$today = strtotime(date("d.m.Y"));
$yesterday = $today - 86400;

$coordinators = $db->getTable("select * from `users` where `type` = 'coordinator1' or `type` = 'coordinator2' order by `user_id`");
$joined = $db->getTable("select `R`.`user_id` from `joined` as `J`,`reports` as `R` where `R`.`report_id` = `J`.`report_id`");
$friends = $db->getColumn("select `R`.`user_id` from `friends` as `F`,`reports` as `R` where `R`.`report_id` = `F`.`report_id`");
$comments = $db->getColumn("select `R`.`user_id` from `comments` as `C`,`reports` as `R` where `R`.`report_id` = `C`.`report_id`");
$topics = $db->getColumn("select `R`.`user_id` from `topics` as `T`,`reports` as `R` where `R`.`report_id` = `T`.`report_id`");

$statistics = array("friends"=>array(),"comments"=>array(),"topics"=>array());
for ($i = 0; $i < 20; $i++)
{
	$statistics['friends'][$i] = 0;
	$statistics['comments'][$i] = 0;
	$statistics['topics'][$i] = 0;
}
foreach($friends as $friend)
	$statistics['friends'][$friend]++;
foreach($comments as $comment)
	$statistics['comments'][$comment]++;
foreach($topics as $topic)
	$statistics['topics'][$topic]++;

require_once ADMIN.DS."head.php";
?>
<div class="full">
	<div class='submenu_container'>
		<a class="submenu_button submenu_button_active" href="/admin/statistics/coordinators">Координаторы</a>
		<a class="submenu_button" href="/admin/statistics/graphs">Графики</a>
	</div>
	
	<h3>Координаторы</h3>
	<div class='text-container'>
		<p>Координаторов онлайн: <?php echo $db->getCell("select count(`user_id`) from `users` where (`type` = 'coordinator1' or `type` = 'coordinator2') and `last_time` > '".(time()-TIME_ONLINE)."'"); ?></p>
		<p>Отчетов за сегодня: <?php echo $db->getCell("select count(`report_id`) from `reports` where `date` >= '$today'"); ?></p>
		<p>Отчетов за вчера: <?php echo $db->getCell("select count(`report_id`) from `reports` where `date` between '$yesterday' and '".($today-1)."'"); ?></p>
		<p>Всего отчетов: <?php echo $db->getCell("select count(`report_id`) from `reports`"); ?></p>
		<br />
		<p>Всего вступило в сообщества: <?php echo count($joined); ?></p>
		<p>Всего добавлено друзей: <?php echo count($friends); ?></p>
		<p>Всего добавлено комментариев: <?php echo count($comments); ?></p>
		<p>Всего добавлено статей: <?php echo count($topics); ?></p>
		<br />
		<table class='coordinator_list'>
			<tr class='table_header'>
				<td>Сообщества</td>
				<td>Координаторы</td>
			</tr>
			<tr>
				<td><span class='group_list'>Цена Оренбургской Жизни</span><br />(вступило людей: <?php
					$peoples = 0;
					foreach ($joined as $join)
						if ($join['user_id'] == 5)
							$peoples++;
					echo $peoples;
				?>)</td>
				<td><?php
					$active = isOnline($coordinators[0]['user_id']) ? "online" : "offline";
					echo "<span class='$active'>".$coordinators[0]['login']."</span> (".$coordinators[0]['sname']." ".$coordinators[0]['name'].")<br />";
					
					$active = isOnline($coordinators[1]['user_id']) ? "online" : "offline";
					echo "<span class='$active'>".$coordinators[1]['login']."</span> (".$coordinators[1]['sname']." ".$coordinators[1]['name'].")
					<br />(друзей: ".$statistics['friends'][$coordinators[1]['user_id']].", комментариев: ".$statistics['comments'][$coordinators[1]['user_id']].", статей: ".$statistics['topics'][$coordinators[1]['user_id']].")";
				?></td>
			</tr>
			<tr>
				<td><span class='group_list'>Оренбургское сообщество неравнодушных людей</span><br />(вступило людей: <?php
					$peoples = 0;
					foreach ($joined as $join)
						if ($join['user_id'] == 7)
							$peoples++;
					echo $peoples;
				?>)</td>
				<td><?php
					$active = isOnline($coordinators[2]['user_id']) ? "online" : "offline";
					echo "<span class='$active'>".$coordinators[2]['login']."</span> (".$coordinators[2]['sname']." ".$coordinators[2]['name'].")<br />";
					
					$active = isOnline($coordinators[3]['user_id']) ? "online" : "offline";
					echo "<span class='$active'>".$coordinators[3]['login']."</span> (".$coordinators[3]['sname']." ".$coordinators[3]['name'].")
					<br />(друзей: ".$statistics['friends'][$coordinators[3]['user_id']].", комментариев: ".$statistics['comments'][$coordinators[3]['user_id']].", статей: ".$statistics['topics'][$coordinators[3]['user_id']].")";
				?></td>
			</tr>
			<tr>
				<td><span class='group_list'>Оренбургское КомпПросвет Училище</span><br />(вступило людей: <?php
					$peoples = 0;
					foreach ($joined as $join)
						if ($join['user_id'] == 9)
							$peoples++;
					echo $peoples;
				?>)</td>
				<td><?php
					$active = isOnline($coordinators[4]['user_id']) ? "online" : "offline";
					echo "<span class='$active'>".$coordinators[4]['login']."</span> (".$coordinators[4]['sname']." ".$coordinators[4]['name'].")<br />";
					
					$active = isOnline($coordinators[5]['user_id']) ? "online" : "offline";
					echo "<span class='$active'>".$coordinators[5]['login']."</span> (".$coordinators[5]['sname']." ".$coordinators[5]['name'].")
					<br />(друзей: ".$statistics['friends'][$coordinators[5]['user_id']].", комментариев: ".$statistics['comments'][$coordinators[5]['user_id']].", статей: ".$statistics['topics'][$coordinators[5]['user_id']].")";
				?></td>
			</tr>
			<tr>
				<td><span class='group_list'>ОРЕНБУРГСКАЯ АЛЬТЕРНАТИВНАЯ БИРЖА ТРУДА</span><br />(вступило людей: <?php
					$peoples = 0;
					foreach ($joined as $join)
						if ($join['user_id'] == 15)
							$peoples++;
					echo $peoples;
				?>)</td>
				<td><?php
					$active = isOnline($coordinators[6]['user_id']) ? "online" : "offline";
					echo "<span class='$active'>".$coordinators[6]['login']."</span> (".$coordinators[6]['sname']." ".$coordinators[6]['name'].")<br />";
					
					$active = isOnline($coordinators[7]['user_id']) ? "online" : "offline";
					echo "<span class='$active'>".$coordinators[7]['login']."</span> (".$coordinators[7]['sname']." ".$coordinators[7]['name'].")
					<br />(друзей: ".$statistics['friends'][$coordinators[7]['user_id']].", комментариев: ".$statistics['comments'][$coordinators[7]['user_id']].", статей: ".$statistics['topics'][$coordinators[7]['user_id']].")";
				?></td>
			</tr>
			<tr>
				<td><span class='group_list'>Я ОРЕНБУРЖЕЦ И ЭТИМ ГОРЖУСЬ!</span><br />(вступило людей: <?php
					$peoples = 0;
					foreach ($joined as $join)
						if ($join['user_id'] == 17)
							$peoples++;
					echo $peoples;
				?>)</td>
				<td><?php
					$active = isOnline($coordinators[8]['user_id']) ? "online" : "offline";
					echo "<span class='$active'>".$coordinators[8]['login']."</span> (".$coordinators[8]['sname']." ".$coordinators[8]['name'].")<br />";
					
					$active = isOnline($coordinators[9]['user_id']) ? "online" : "offline";
					echo "<span class='$active'>".$coordinators[9]['login']."</span> (".$coordinators[9]['sname']." ".$coordinators[9]['name'].")
					<br />(друзей: ".$statistics['friends'][$coordinators[9]['user_id']].", комментариев: ".$statistics['comments'][$coordinators[9]['user_id']].", статей: ".$statistics['topics'][$coordinators[9]['user_id']].")";
				?></td>
			</tr>
		</table>
	</div>
</div>
<?php require_once ADMIN.DS."footer.php"; ?>
